<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class MY_Controller extends CI_Controller {

    /**
     * Index Page for this controller.
     *
     * Maps to the following URL
     * 		http://example.com/index.php/welcome
     * 	- or -  
     * 		http://example.com/index.php/welcome/index
     * 	- or -
     * Since this controller is set as the default controller in 
     * config/routes.php, it's displayed at http://example.com/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/welcome/<method_name>
     * @see http://codeigniter.com/user_guide/general/urls.html
     */
    public function __construct() {
        parent::__construct();
        $this->load->library('nativesession');
        $this->load->library('form_validation');
        $this->load->library('pagination');
        $this->load->library("MPDF57/mpdf");
        $this->load->library('get_value');
        $this->load->library('MY_Session');
        $this->load->helper('url');
        $this->load->model('general_model');





        if ($this->nativesession->userdata('logged_in')) {
            $session_data = $this->nativesession->userdata('logged_in');
            $this->user_id = $session_data['user_id'];
            $this->usertype = $session_data['usertype'];
            $this->username = $session_data['username'];
            $this->password = $session_data['password'];
        }
        echo "<meta charset='utf-8'>";
    }

    public function core_view($view = NULL, $param = NULL) {

        //ค่อยเช็ค session แล้วโหลด view
        $this->load->view('head_view'); //head
        if ($view != NULL) {
            $this->load->view($view, $param);
        }
        $this->load->view('footter_view'); //foot
    }

    public function core_admin_view($view = NULL, $param = NULL) {

        //ค่อยเช็ค session แล้วโหลด view
        $this->load->view('admin/head_view'); //head
        if ($view != NULL) {
            $this->load->view($view, $param);
        }
        $this->load->view('admin/footter_view'); //foot
    }

    public function core_doctor_view($view = NULL, $param = NULL) {

        //ค่อยเช็ค session แล้วโหลด view
        $this->load->view('doctor/head_view'); //head
        if ($view != NULL) {
            $this->load->view($view, $param);
        }
        $this->load->view('doctor/footter_view'); //foot
    }

    public function core_staff_view($view = NULL, $param = NULL) {

        //ค่อยเช็ค session แล้วโหลด view
        $this->load->view('staff/head_view'); //head
        if ($view != NULL) {
            $this->load->view($view, $param);
        }
        $this->load->view('staff/footter_view'); //foot
    }

    public function core_tech_view($view = NULL, $param = NULL) {

        //ค่อยเช็ค session แล้วโหลด view
        $this->load->view('tech/head_view'); //head
        if ($view != NULL) {
            $this->load->view($view, $param);
        }
        $this->load->view('tech/footter_view'); //foot
    }

    public function pagination($page, $url, $total_rows, $per_page, $uri_segment) {
        if ($this->router->fetch_method() != '') {
            $url = base_url() . $this->router->fetch_class() . '/' . $this->router->fetch_method();
        } else {
            $url = base_url() . $this->router->fetch_class() . '/index';
        }
        // var_dump($url);die();
        $config['base_url'] = $url;
        $config['total_rows'] = $total_rows;
        $config['per_page'] = $per_page;
        $config['uri_segment'] = $uri_segment;


        if ($page == '' or $page <= '1') {
            $this->start_no = 0;
        } else {
            $this->start_no = ( ($page * $this->per_page) - $this->per_page);
        }
        // var_dump($page);die();

        $this->pagination->initialize($config);
        $this->my_pagination = $this->pagination->create_links();
    }

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */